import hasRole from './permission/hasRole'
import hasPermi from './permission/hasPermi'
import dialogDrag from './dialog/drag'
import dialogDragWidth from './dialog/dragWidth'
import dialogDragHeight from './dialog/dragHeight'
import clipboard from './module/clipboard'

const install = function(Vue) {
  Vue.directive('hasRole', hasRole)
  Vue.directive('hasPermi', hasPermi)
  Vue.directive('clipboard', clipboard)
  Vue.directive('dialogDrag', dialogDrag)
  Vue.directive('dialogDragWidth', dialogDragWidth)
  Vue.directive('dialogDragHeight', dialogDragHeight)
  // 注册一个全局自定义指令 `v-mybatis`
  Vue.directive('mybatis', {
    inserted: function (el, binding, vnode) {
      // 尝试解析 binding.value 以提取字段名和查询方法
      const value = binding.value;
      if (vnode.context) {
        // 确保组件实例中存在 mybatisPlusMethods 对象
        if (!vnode.context.mybatisPlusMethods) {
          vnode.context.mybatisPlusMethods = {};
        }
        // 直接从对象中读取字段名和查询方法
        for (const [fieldName, queryMethod] of Object.entries(value)) {
          vnode.context.mybatisPlusMethods[fieldName] = queryMethod;
        }
      }
    }
  })
}

if (window.Vue) {
  window['hasRole'] = hasRole
  window['hasPermi'] = hasPermi
  Vue.use(install); // eslint-disable-line
}

export default install
